package dk.com.entities;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class H2ConnectionBuilder {
	private Connection conn;
	private Statement stat;

	public H2ConnectionBuilder() throws ClassNotFoundException, SQLException {
		Class.forName("org.h2.Driver");
		if(conn == null || conn.isClosed()){
			conn = DriverManager.getConnection("jdbc:h2:file:///E:/Library/GoogleDrive/Plan/Amway/Project/db/testdb","sa","");
		}
    	stat = conn.createStatement();
	}

	public Statement getStat() {
		return stat;
	}
	public void closeConnection(){
		try {
			this.conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

//
//		        try {
//		        	try {
//						Class.forName("org.h2.Driver");
//					} catch (ClassNotFoundException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//					}
//		        	Connection conn = DriverManager.getConnection("jdbc:h2:file:///E:/Library/GoogleDrive/Plan/Amway/Project/db/testdb","sa","");
//		        	Statement stat = conn.createStatement();
//					ResultSet rs;
//					rs = stat.executeQuery("select * from UserData");
//					while (rs.next()) {
//						System.out.println(rs.getString("name"));
//					}
//					stat.close();
//					conn.close();
//				} catch (SQLException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}